#!/usr/bin/ruby -Ku
# -*- coding: utf-8 -*-
require 'test/unit'
require 'm3g'

class Test_Texture2D < Test::Unit::TestCase
  def setup
  end

  def teadown
  end

  def test_default_variables
    img = M3G::Image2D.new M3G::Image2D::RGBA, 64, 64
    tex = M3G::Texture2D.new img

    assert_equal img                              , tex.image
    assert_equal M3G::Texture2D::WRAP_REPEAT      , tex.wrapping.s
    assert_equal M3G::Texture2D::WRAP_REPEAT      , tex.wrapping.t
    assert_equal M3G::Texture2D::FILTER_BASE_LEVEL, tex.filter.level
    assert_equal M3G::Texture2D::FILTER_NEAREST   , tex.filter.image
    assert_equal M3G::Texture2D::FUNC_MODULATE    , tex.blending
  end

  def test_set_variables
    img1 = M3G::Image2D.new M3G::Image2D::RGBA, 64, 64
    img2 = M3G::Image2D.new M3G::Image2D::RGBA, 64, 64
    tex  = M3G::Texture2D.new img1

    tex.blend_color = 0xfe345678
    tex.blending    = M3G::Texture2D::FUNC_BLEND
    tex.filtering   = M3G::Texture2D::FILTER_LINEAR, M3G::Texture2D::FILTER_LINEAR
    tex.image       = img2
    tex.wrapping    = M3G::Texture2D::WRAP_CLAMP, M3G::Texture2D::WRAP_CLAMP

    assert_equal img2, tex.image
    assert_equal M3G::Texture2D::WRAP_CLAMP   , tex.wrapping.s
    assert_equal M3G::Texture2D::WRAP_CLAMP   , tex.wrapping.t
    assert_equal M3G::Texture2D::FILTER_LINEAR, tex.filter.level
    assert_equal M3G::Texture2D::FILTER_LINEAR, tex.filter.image
    assert_equal M3G::Texture2D::FUNC_BLEND   , tex.blending
  end

  def test_duplicate
    img1 = M3G::Image2D.new M3G::Image2D::RGBA, 64, 64
    img2 = M3G::Image2D.new M3G::Image2D::RGBA, 64, 64
    tex1 = M3G::Texture2D.new img1

    tex1.blend_color = 0xfe345678
    tex1.blending    = M3G::Texture2D::FUNC_BLEND
    tex1.filtering   = M3G::Texture2D::FILTER_LINEAR, M3G::Texture2D::FILTER_LINEAR
    tex1.image       = img2
    tex1.wrapping    = M3G::Texture2D::WRAP_CLAMP, M3G::Texture2D::WRAP_CLAMP

    tex2 = tex1.duplicate

    assert_equal img2, tex2.image
    assert_equal M3G::Texture2D::WRAP_CLAMP   , tex2.wrapping.s
    assert_equal M3G::Texture2D::WRAP_CLAMP   , tex2.wrapping.t
    assert_equal M3G::Texture2D::FILTER_LINEAR, tex2.filter.level
    assert_equal M3G::Texture2D::FILTER_LINEAR, tex2.filter.image
    assert_equal M3G::Texture2D::FUNC_BLEND   , tex2.blending
  end

  def test_references
    img = M3G::Image2D.new M3G::Image2D::RGBA, 64, 64
    tex = M3G::Texture2D.new img

    objs = tex.references

    assert_equal 1  , objs.length
    assert_equal img, objs[0]
  end
end
